#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

typedef struct HASHTABLE HashTable;
typedef struct HASHITEM  ElementType;
struct HASHTABLE{
	ElementType *Elm;
	_Bool *Info;
	int TableSize;
};
struct HASHITEM{
	long Account;
	char Pwd[17];
};

#define TABLE_SIZE 180001
#define EMPTY	false
#define OCCUPY	true
//	Create Account
#define CREATE_OK 1
#define ACCOUNT_EXIST 0
//	Login
#define ACCOUNT_NO_EXIST -2
#define WRONG_PASSWD	-1
#define LOGIN_OK		1

int NextPrime(int a);
int HashValue(HashTable*,long);
HashTable *HashTableInit(void);
_Bool InsertHashTable(HashTable*,ElementType);
int	FindPos(HashTable*,ElementType);
_Bool CreateAccount(HashTable*,ElementType);
int Login(HashTable*,ElementType);

int NextPrime(int a){
	if( a <= 2 )return 2;
	do{
		int i;
		for( i=2 ; i*i < a ; i++ ){
			if( a%i == 0 )
				break;
		}
		if( i*i > a )
			break;
	}while( a++ );
	return a;
}
HashTable *HashTableInit(void){
	HashTable *h=malloc(sizeof(HashTable));
	h->TableSize=TABLE_SIZE;
	h->Elm=malloc(sizeof(ElementType)*h->TableSize);
	h->Info=malloc(sizeof(_Bool)*h->TableSize);
	memset(h->Info,EMPTY,sizeof(_Bool)*h->TableSize);
	return h;
}
int HashValue(HashTable *h,long key){
	return key%(h->TableSize);
}
_Bool InsertHashTable(HashTable *h,ElementType elm){
	int currentPos=HashValue(h,elm.Account);
	int newPos=currentPos;
	int count=1;
	int m;
	while( h->Info[newPos] == OCCUPY && count <= h->TableSize/2 ){
		m=(count)%2;
		if( m )
			newPos=(currentPos+(count+1)*(count+1)/4)%h->TableSize;
		else
			newPos=(currentPos-count*count/4)%h->TableSize;
		count++;
	}
	if( count > h->TableSize/2 ){
		printf("Insert Error\n");
		return false;
	}
	h->Info[newPos]=OCCUPY;
	h->Elm[newPos].Account=elm.Account;
	strcpy(h->Elm[newPos].Pwd,elm.Pwd);
	//h->Elm[newPos]=elm;
	return true;
}
int	FindPos(HashTable *h,ElementType elm){
	int currentPos,newPos;
	newPos=currentPos=HashValue(h,elm.Account);
	int count=1,m;
	while( h->Info[newPos] == OCCUPY && h->Elm[newPos].Account != elm.Account ){
		m=(count)%2;
		if( m )
			newPos=(currentPos+(count+1)*(count+1)/4)%h->TableSize;
		else
			newPos=(currentPos-count*count/4)%h->TableSize;
		count++;
	}
	if( h->Info[newPos] == EMPTY )
		return -1;
	else
		return newPos;
}
_Bool CreateAccount(HashTable *h,ElementType elm){
	if( -1 != FindPos(h,elm) ){	// Account Exist
		return false;
	}
	else{
		InsertHashTable(h,elm);
		return true;
	}
}
//#define ACCOUNT_NO_EXIST -2
//#define WRONG_PASSWD	-1
//#define LOGIN_OK		1
int Login(HashTable *h,ElementType elm){
	int pos=FindPos(h,elm);
	if( -1 == pos )
		return ACCOUNT_NO_EXIST;
	if( 0 == strcmp(elm.Pwd,h->Elm[pos].Pwd) ){
		return LOGIN_OK;
	}else{
		return WRONG_PASSWD;
	}
}
int main(void){
//	Init
//printf("%d\n",NextPrime(300004));
	HashTable *h=HashTableInit();
	int N;
	char Cmd[2];
	long QQ;
	char Pwd[17];
	int result;
	ElementType e;
//	-----------------------------------------
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%s%ld%s",Cmd,&QQ,Pwd);
		e.Account=QQ;
		strcpy(e.Pwd,Pwd);
		if( strcmp(Cmd,"L") == 0 ){
			result=Login(h,e);
			if( ACCOUNT_NO_EXIST == result ){
				printf("ERROR: Not Exist\n");
			}else if( LOGIN_OK == result ){
				printf("Login: OK\n");
			}else{
				printf("ERROR: Wrong PW\n");
			}
		}else if( strcmp(Cmd,"N") == 0 ){
			if( CreateAccount(h,e) ){
				printf("New: OK\n");
			}else{
				printf("ERROR: Exist\n");
			}
		}else{}
	}
	return 0;
}
